package com.example.jpademo.Controller;

import com.example.jpademo.Entity.Author;
import com.example.jpademo.Service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/author")
public class AuthorController {
    @Autowired
    AuthorService authorService;
    @GetMapping("/findAll")
    public List<Author> findAll(){
        return authorService.getAllAuthor();
    }
    @PostMapping("/register")
    public Author save(@RequestBody Author author){
        authorService.addAuthor(author);
        return author;
    }
    @PostMapping("/login")
    public String login(@RequestBody Author author) {
        return authorService.login(author);
    }
    //改信息
    @PostMapping("/update")
    public Author update(@RequestBody Author author){
        authorService.updateAuthor(author);
        return author;
    }
    //删
    @DeleteMapping(value = "/deleteById/{id}")
    public void deleteById(@PathVariable("id") Integer id){
        authorService.deleteAuthor(id);
    }
}
